package org.servlet;

import org.domain.Account;
import org.domain.Order;
import org.service.AccountService;
import org.service.OrderService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

public class newOrderFinishServlet extends HttpServlet {
    private static final String LIST_ORDER = "/WEB-INF/JSP/order/ListOrders.jsp";
    private OrderService orderService;

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        orderService = new OrderService();

        HttpSession session = request.getSession();
        Account account = (Account) session.getAttribute("account");

        List<Order> orderList = orderService.getOrdersByUsername(account.getUsername());
        session.setAttribute("orderList", orderList);
        request.getRequestDispatcher(LIST_ORDER).forward(request, response);
    }
}
